<?php
class teleController extends AController {
	public function saveRecordAction() {
		$teleNo = $this->request->getPostParameter('telNo');
		$callType = $this->request->getPostParameter('callType');
		$startTime = $this->request->getPostParameter('startTime');
		$endTime = $this->request->getPostParameter('endTime');
		$duration = $this->request->getPostParameter('duration');
		$fileName = $this->request->getPostParameter('fileName');
		$row = array(
				'TEL_NO'=>$teleNo,
				'CALL_TYPE'=>$callType,
				'START_TIME'=>$startTime,
				'END_TIME'=>$endTime,
				'DURATION'=>$duration,
				'FILE_NAME'=>$fileName,
				'USER_ID'=>CSM_USER_ID,
				'USER_NAME'=>CSM_USER_NAME,
				'UNIT_ID'=>CSM_UNIT_ID);
		$rs = JYDB::create('TELRECORD', $row, 'ID');
		if ($rs) {
			return json_encode(array('code'=>'1', 'msg'=>'电话记录成功'));
		} else {
			return json_encode(array('code'=>'0', 'msg'=>'电话记录失败'));
		}
	}
	
	public function checklastAction() {
		$teleNo = $this->request->getGetParameter('tele');
		// 判断 7 天之内是否有电话记录，如果有，则取出最近7天之内的通话记录（时长 > 40秒表示有效）
		$date = date('Y-m-d h:i:s', strtotime('-8 days'));
		$rows = JYDB::findAll('TELRECORD', "TEL_NO='{$teleNo}' AND START_TIME>'{$date}'", '*', 'ID DESC');
		if ($rows) {
			$this->rows = $rows;
			$html = $this->render();
			return json_encode(array('count'=>count($rows), 'html'=>$html));
		} else {
			return json_encode(array('count'=>0));
		}
	}
}